package com.light.mapcomponents;

import javax.microedition.khronos.opengles.GL10;

import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.shape.Shape;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.extension.physics.box2d.PhysicsFactory;
import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.huw.debuger.Debugger;
import com.light.gamecomponents.IGameComponents;
import com.light.roller.Roller;

public class StaticWall implements IGameComponents{
	
	protected Shape m_shape;
	protected Sprite m_sprite;
	protected String m_textureName;
	protected Body m_body;
	protected FixtureDef m_fixtureDef;
	protected float m_rotation;
	

	public StaticWall(Shape shape, String textureName, float rotation)
	{
		FixtureDef tempFixtureDef = PhysicsFactory.createFixtureDef(0, 0.0f, 1.0f);
		tempFixtureDef.filter.categoryBits = Roller.CATEGORYBIT_WALL;
		tempFixtureDef.filter.maskBits = Roller.MASKBIT_WALL;
		m_shape = shape;
		m_textureName = textureName;
		m_fixtureDef = tempFixtureDef;
		m_rotation = rotation;
	}
	
	public int getX1() {

		return (int) m_shape.getX();
	}

	public int getX2() {

		return (int)(m_shape.getX()+m_shape.getWidth());
	}

	public int getY1() {

		return (int) m_shape.getY();
	}

	public int getY2() {

		return (int)(m_shape.getY()+m_shape.getHeight());
	}
	
	@Override
	public void onLoadResources() {
		
	}
	@Override
	public void onLoadScene(Scene scene, PhysicsWorld physicsWorld) { 
		
		m_shape.setBlendFunction(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
		if(Debugger.AlPHA_STATIC_WALL)
			m_shape.setAlpha(0.3f);
		m_shape.setRotation(m_rotation);
		m_body = PhysicsFactory.createBoxBody(physicsWorld, m_shape, BodyType.StaticBody, m_fixtureDef);
		if (!Debugger.HIDE_STATIC_WALL)
			scene.attachChild(m_shape);
	}

	@Override
	public void onLoadEngine() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void unLoadResources() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void removeFromScene(Scene scene, PhysicsWorld physicsWorld) {
		scene.detachChild(m_shape);
		physicsWorld.destroyBody(m_body);
	}
	@Override
	public void rotate(float angle) {
		// TODO Auto-generated method stub
		
	}
}
